package com.iptv.grape.event.imp;

import com.google.gson.Gson;
import com.iptv.grape.BaseActivity;
import com.iptv.grape.bu.GrapeContext;
import com.iptv.grape.event.EventArgs;
import com.iptv.grape.event.JSRequest;
import com.iptv.grape.event.msg.IntoChannelData;
import com.iptv.grape.event.msg.IntoFullScreenProcArgs;
import com.iptv.grape.event.msg.IntoFullScreenProcData;
import com.iptv.grape.event.proc.IWebViewMessageProc;
import com.iptv.grape.util.AppLog;
import com.iptv.grape.video.XMediaPlayer;

import org.greenrobot.eventbus.EventBus;

// 从播放小窗口 进入全屏事件
public class IntoFullScreenProc implements IWebViewMessageProc {

    private IntoFullScreenProcData argsData;

    @Override
    public void init(JSRequest jsRequest) {
        try {
            //AppLog.getCurLog().out(jsRequest.getJson());
            argsData = new Gson().fromJson(jsRequest.getJson(), IntoFullScreenProcData.class);
            if(argsData != null){
                AppLog.getCurLog().out(argsData.getData().getModeType());
            }
        }
        catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public String procMessage(BaseActivity baseActivity, XMediaPlayer mediaPlayer) {
        //EventBus.getDefault().post(new EventArgs("IntoFullScreenProc", "JsEvent",null));
        mediaPlayer.fullScreen();
        GrapeContext.curGrapeContext().setFocus(true);
        GrapeContext.curGrapeContext().setFullScreen(true);
        if(argsData !=null && argsData.getData() != null) {
            if ("3".equals(argsData.getData().getModeType())) {
                // 全部频道 3
                GrapeContext.curGrapeContext().loadLiveMenu(baseActivity,3);
            }
            if ("4".equals(argsData.getData().getModeType())) {
                // 热门频道 0
                GrapeContext.curGrapeContext().loadLiveMenu(baseActivity,0);
            }
            if ("5".equals(argsData.getData().getModeType())) {
                // 回看频道 4
                GrapeContext.curGrapeContext().loadLiveMenu(baseActivity,4);
            }
        }
        // 指示退出全屏时 不需要关闭播放器
        GrapeContext.curGrapeContext().setQuitFullScreenStopPlay(false);
        return "";
    }
}
